package com.dupt.web.controller.maintenance;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.dupt.system.domain.param.MaintenanceParam;
import com.dupt.system.domain.param.MaintenanceVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dupt.common.annotation.Log;
import com.dupt.common.core.controller.BaseController;
import com.dupt.common.core.domain.AjaxResult;
import com.dupt.common.enums.BusinessType;
import com.dupt.system.domain.MaterialMaintenance;
import com.dupt.system.service.IMaterialMaintenanceService;
import com.dupt.common.utils.poi.ExcelUtil;
import com.dupt.common.core.page.TableDataInfo;

/**
 * 维保信息Controller
 * 
 * @author zhuanyu.sun
 * @date 2025-07-22
 */
@RestController
@RequestMapping("/maintenance")
public class MaterialMaintenanceController extends BaseController
{
    @Autowired
    private IMaterialMaintenanceService materialMaintenanceService;

    /**
     * 查询维保信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:maintenance:list')")
    @GetMapping("/list")
    public TableDataInfo list(MaintenanceParam maintenanceParam)
    {
        startPage();
        List<MaintenanceVo> list = materialMaintenanceService.selectMaterialMaintenanceList(maintenanceParam);
        return getDataTable(list);
    }

    /**
     * 导出维保信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:maintenance:export')")
    @Log(title = "维保信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MaintenanceParam maintenanceParam)
    {
        List<MaintenanceVo> list = materialMaintenanceService.selectMaterialMaintenanceList(maintenanceParam);
        ExcelUtil<MaintenanceVo> util = new ExcelUtil<MaintenanceVo>(MaintenanceVo.class);
        util.exportExcel(response, list, "维保信息数据");
    }

    /**
     * 获取维保信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:maintenance:query')")
    @GetMapping(value = "/{maintenanceId}")
    public AjaxResult getInfo(@PathVariable("maintenanceId") Long maintenanceId)
    {
        return success(materialMaintenanceService.selectMaterialMaintenanceByMaintenanceId(maintenanceId));
    }

    /**
     * 新增维保信息
     */
    @PreAuthorize("@ss.hasPermi('system:maintenance:add')")
    @Log(title = "维保信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MaterialMaintenance materialMaintenance)
    {
        return toAjax(materialMaintenanceService.insertMaterialMaintenance(materialMaintenance));
    }

    /**
     * 修改维保信息
     */
    @PreAuthorize("@ss.hasPermi('system:maintenance:edit')")
    @Log(title = "维保信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MaterialMaintenance materialMaintenance)
    {
        return toAjax(materialMaintenanceService.updateMaterialMaintenance(materialMaintenance));
    }

    /**
     * 删除维保信息
     */
    @PreAuthorize("@ss.hasPermi('system:maintenance:remove')")
    @Log(title = "维保信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{maintenanceIds}")
    public AjaxResult remove(@PathVariable Long[] maintenanceIds)
    {
        return toAjax(materialMaintenanceService.deleteMaterialMaintenanceByMaintenanceIds(maintenanceIds));
    }
}
